﻿using System.Collections.Generic;

namespace USClientKernel.MVC
{
    public delegate void OnDataEventHandler<T>(T data) where T : BaseData<T>;

    public abstract class BaseData<T> : BaseCast<T>, IBaseData<T> where T : BaseData<T>
    {
        protected event OnDataEventHandler<T> EventHandler;
        public virtual void DispatchDataEvent(T _data)
        {
            EventHandler?.Invoke(_data);
        }

        private T m_parent;
        public T Parent { get => m_parent; set => m_parent = value; }

        private List<T> m_children;
        public List<T> Children { get => m_children; set => m_children = value; }

        private ulong m_guid;
        public ulong GUID { get => m_guid; }
        public virtual void SetGuid(ulong _guid) { m_guid = _guid; }

        private string m_name;
        public string Name { get => m_name; set => m_name = value; }

        public abstract void InsertChild(T _data);
        public abstract void RemoveChild(T _data);
        public abstract void RemoveChildren();
        public abstract void RemoveFromParent();


        public virtual void RegisterDataEventHandler(OnDataEventHandler<T> handler)
        {
            EventHandler += handler;
        }

        public virtual void UnregisterDataEventHandler(OnDataEventHandler<T> handler)
        {
            EventHandler -= handler;
        }
    }
}
